// TOWN SCRIPT
//    Town 7: Proving Grounds - Seventh Level

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

// flags:
// 7, 27 = balanced pre-sets
// 7, 28 = presets all gone
// 7, 29 = generate new monsters

begintownscript;

variables;

short i, j, x, y, choice;

body;

beginstate INIT_STATE;
	turn_off_training(1);
	set_crime_tolerance(1);

	// check monsters...
	run_scenario_script(21);
	if (get_flag(7, 29) > 0) {
		// generate some more...
		set_flag(7, 29, 0);
		print_str_color("Generating monsters...", 3);
		j = get_ran(1, 14, 24);
		i = 0;
		while (i < j) {
			run_scenario_script(33);
			if (get_flag(100, 0) > 0) {
				run_scenario_script(26);
				place_monster(get_flag(100, 1), get_flag(100, 2), get_flag(100, 0), 0);
			}
			i = i + 1;
		}
		run_scenario_script(42);
	}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
break;

beginstate 10;
	reset_dialog();
	add_dialog_str(0, "There is an elevator here.", 0);
	add_dialog_str(1, "Use?", 0);
	add_dialog_choice(0, "No");
	add_dialog_choice(1, "Yes");
	choice = run_dialog(0);
	if (choice == 2) {
		block_entry(1);
		i = 0;
		while (i == 0) {
			get_text_response("Which level (A-F), D exits");
			check_text_response_match("A");
			if (got_text_match() > 0) {
				move_to_new_town(4, 24, 43);
				end();
			}
			check_text_response_match("B");
			if (got_text_match() > 0) {
				move_to_new_town(5, 23, 43);
				end();
			}
			check_text_response_match("C");
			if (got_text_match() > 0) {
				move_to_new_town(6, 24, 43);
				end();
			}
			check_text_response_match("D");
			if (got_text_match() > 0) {
				block_entry(0);
				// move_to_new_town(7, 24, 43);
				end();
			}
			check_text_response_match("E");
			if (got_text_match() > 0) {
				move_to_new_town(8, 24, 9);
				end();
			}
			check_text_response_match("F");
			if (got_text_match() > 0) {
				move_to_new_town(9, 24, 43);
				end();
			}
		}
	}
break;

beginstate 11;
	block_entry(1);
	reset_dialog();
	add_dialog_str(0, "There is a ladder leading up to the previous level.", 0);
	add_dialog_choice(0, "Leave");
	add_dialog_choice(1, "Climb up");
	choice = run_dialog(0);
	if (choice == 2) {
		// ladder back up...
		move_to_new_town(6, 21, 7);
	}
break;

beginstate 12;
	block_entry(1);
	reset_dialog();
	add_dialog_str(0, "There is a trapdoor leading into darkness below.", 0);
	add_dialog_choice(0, "Leave");
	add_dialog_choice(1, "Drop down");
	choice = run_dialog(0);
	if (choice == 2) {
		// going down / no turning back this way...
		move_to_new_town(8, 26, 32);
	}
break;

beginstate 13;
	block_entry(1);
	x = char_loc_x(0);
	y = char_loc_y(0);
	if (y >= 40) {
		y = 3;
	}
	else {
		y = 44;
	}
	teleport_party(x, y, 1);
break;

beginstate 14;
	block_entry(1);
	x = char_loc_x(0);
	y = char_loc_y(0);
	if (x >= 40) {
		x = 3;
	}
	else {
		x = 44;
	}
	teleport_party(x, y, 1);
break;

beginstate 15;
	run_scenario_script(11);
break;

beginstate 16;
	teleport_party(44, 44, 1);
break;

beginstate 17;
	teleport_party(44, 19, 1);
break;

beginstate 18;
	teleport_party(31, 31, 1);
break;
